package cn.com;

import cn.com.common.config.SnowflakeIdWorker;
import cn.com.common.config.GasstationConfig;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class,DruidDataSourceAutoConfigure.class, FreeMarkerAutoConfiguration.class })
@MapperScan({ "cn.com.nr.mapper",
			  "cn.com.system.mapper",
		      "cn.com.gt3.mapper",
		      "cn.com.gas.mapper",
		      "cn.com.statistics.mapper",
		      "cn.com.thirdparty.mapper",
		      "cn.com.integration.mapper"})
public class GasstationApplicationStart {

	@Autowired
	private GasstationConfig gasstationConfig;

	public static void main(String[] args) throws UnknownHostException {
		ConfigurableApplicationContext application = SpringApplication.run(GasstationApplicationStart.class, args);
		log.info("-------------启动成功------------");
		
		Environment env = application.getEnvironment();
		log.info("\n----------------------------------------------------------\n\t"
				+ "Application '{}' is running! Access URLs:\n\t" + "Login: \thttp://{}:{}/login\n\t"
				+ "Doc: \thttp://{}:{}/doc.html\n" + "----------------------------------------------------------",
				env.getProperty("spring.application.name"), InetAddress.getLocalHost().getHostAddress(),
				env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(),
				env.getProperty("server.port"));
	}

	@Bean
	public SnowflakeIdWorker snowflakeIdWorker() {
		return new SnowflakeIdWorker(gasstationConfig.getWorkerId(), gasstationConfig.getDatacenterId());
	}

}
